/*
222. 完全二叉树的节点个数
https://leetcode.cn/problems/count-complete-tree-nodes/submissions/?envType=problem-list-v2&envId=binary-search
难度：简单   李佳韵 2024/09/14
二分查找
*/

/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left),
 * right(right) {}
 * };
 */
class Solution {
public:
    int countNodes(TreeNode* root) {
        if (!root)
            return 0;
        return countNodes(root->left) + countNodes(root->right) + 1;
    }
};
